package com.study.talk.utils.extras

import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import com.study.common.GSONUtil
import com.study.talk.ui.app.chat.ChatActivity
import com.study.talk.ui.app.chat.GroupChatActivity
import com.study.talk.ui.app.friend.UserDetailsActivity
import com.study.talk.ui.app.group.InviteFriendActivity
import com.study.talk.ui.app.group.info.GroupInfoActivity
import com.study.talk.ui.app.moment.MomentsActivity
import com.study.talk.ui.app.other.ImagePreviewActivity

fun <T : AppCompatActivity> Context.start(target: Class<T>, params: (Intent) -> Unit){
    val intent = Intent(this, target)
    params(intent)
    startActivity(intent)
}

fun <T : AppCompatActivity> Context.start(target: Class<T>){
    startActivity(Intent(this, target))
}

fun Context.toChat(userId: Int) {
    start(ChatActivity::class.java) {
        it.putExtra(ChatActivity.DATA_NAME, userId)
    }
}

fun Context.toGroupChat(groupId: Int) {
    start(GroupChatActivity::class.java) {
        it.putExtra(GroupChatActivity.DATA_NAME, groupId)
    }
}

fun Context.toUserDetails(userId: Int) {
    start(UserDetailsActivity::class.java) {
        it.putExtra(UserDetailsActivity.DATA_NAME, userId)
    }
}

fun Context.toGroupInfo(groupId: Int) {
    start(GroupInfoActivity::class.java) {
        it.putExtra(GroupInfoActivity.DATA_NAME, groupId)
    }
}

fun Context.toInviteFriend(groupId: Int) {
    start(InviteFriendActivity::class.java) {
        it.putExtra(InviteFriendActivity.DATA_NAME, groupId)
    }
}

fun Context.toMoments(type: Int, userId: Int) {
    start(MomentsActivity::class.java){
        it.putExtra(MomentsActivity.DATE_NAME,userId)
        it.putExtra(MomentsActivity.TYPE_NAME,type)
    }
}

fun Context.toImage(images: List<String>, index:Int) {
    start(ImagePreviewActivity::class.java){
        it.putExtra(ImagePreviewActivity.IMAGES, GSONUtil.toJson(images))
        it.putExtra(ImagePreviewActivity.INDEX,index)
    }
}